<?php

namespace app\admin\controller;

use think\Controller;

class Ajax extends Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 验证登录
     */
    public function dologin()
    {
        $post = input();
        if ($post['name']) {
            if ($post['pwd']) {
                $res = controller('data')->dologin($post['name'], $post['pwd']);
                $return['status'] = $res['status'];
                $return['mes'] = $res['mes'];
                if ($res['status'] == 200) {
                    session('admin', $res['info']);
                }
            } else {
                $return['status'] = 401;
                $return['mes'] = "请输入密码";
            }
        } else {
            $return['status'] = 400;
            $return['mes'] = "请输入用户名";
        }
        return json($return);
    }


    /*
     * 退出登录
     */

    public function login_out()
    {
        $aa = session('admin', null);
        $return['status'] = 200;
        $return['mes'] = "正在退出系统。。。";
        return json($return);
    }


    public function upload()
    {
        $file = upload_img('upload_img', 'news');
        if ($file['status'] == 200) {
            $return = $file;
        } else {
            $return['mes'] = "上传失败";
            $return['status'] = 404;
        }
        return json($return);
    }
}
